home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / midas060 / src / errors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-16  |  5.4 KB  |  232 lines

  1. /*      ERRORS.C
  2.  *
  3.  * MIDAS Sound System error codes and error message strings
  4.  *
  5.  * $Id: errors.c,v 1.4 1996/07/13 20:33:43 pekangas Exp $
  6.  *
  7.  * Copyright 1996 Petteri Kangaslampi and Jarno Paananen
  8.  *
  9.  * This file is part of the MIDAS Sound System, and may only be
  10.  * used, modified and distributed under the terms of the MIDAS
  11.  * Sound System license, LICENSE.TXT. By continuing to use,
  12.  * modify or distribute this file you indicate that you have
  13.  * read the license and understand and accept it fully.
  14. */
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include "lang.h"
  19. #include "mtypes.h"
  20. #include "errors.h"
  21. #ifndef __LINUX__
  22. #include "vgatext.h"
  23. #endif
  24.  
  25. RCSID(const char *errors_rcsid = "$Id: errors.c,v 1.4 1996/07/13 20:33:43 pekangas Exp $";)
  26.  
  27.  
  28. /* maximum length of an error message is 40 characters! */
  29.  
  30. char            *errorMsg[] =
  31. {
  32.     "OK",
  33.     "Undefined error",
  34. #ifdef __REALMODE__
  35.     "Out of conventional memory",
  36.     "Conventional memory heap corrupted",
  37.     "Invalid conventional memory block",
  38. #else
  39.     "Out of memory",
  40.     "Heap corrupted",
  41.     "Invalid memory block",
  42. #endif
  43.     "Out of EMS memory",
  44.     "EMS memory heap corrupted",
  45.     "Invalid EMS memory block",
  46.     "Expanded Memory Manager failure",
  47.     "Out of soundcard memory",
  48.     "Soundcard memory heap corrupted",
  49.     "Invalid soundcard memory block",
  50.     "Out of sample handles",
  51.     "Unable to open file",
  52.     "Unable to read file",
  53.     "Invalid module file",
  54.     "Invalid instrument in module",
  55.     "Invalid pattern data in module",
  56.     "Invalid channel number",
  57.     "Invalid sample handle",
  58.     "Sound Device channels not open",
  59.     "Sound Device hardware failure",
  60.     "Invalid function arguments",
  61.     "File does not exist",
  62.     "Invalid file handle",
  63.     "Access denied",
  64.     "File exists",
  65.     "Too many open files",
  66.     "Disk full",
  67.     "Unexpected end of file",
  68.     "Invalid path",
  69.     "Unable to write file",
  70.     "Unable to lock Virtual DMA buffer",
  71.     "Unable to use Virtual DMA Services",
  72.     "Invalid Virtual DMA Service version",
  73.     "DPMI failure",
  74.     "Invalid segment descriptor",
  75.     "Out of system resources",
  76.     "Invalid device used",
  77.     "Unsupported function used" ,
  78.     "Device is not available",
  79.     "Device is busy",
  80.     "Unsupported output mode used",
  81.     "Unable to lock memory"
  82. };
  83.  
  84.  
  85.  
  86.  
  87. #ifdef DEBUG
  88.  
  89. errRecord   errorList[MAXERRORS];       /* error list */
  90. unsigned    numErrors = 0;              /* number of errors in list */
  91.  
  92.  
  93.  
  94. /****************************************************************************\
  95. *
  96. * Function:     void errAdd(int errorCode, unsigned functID);
  97. *
  98. * Description:  Add an error to error list
  99. *
  100. * Input:        int errorCode           error code
  101. *               unsigned functID        ID for function that caused the error
  102. *
  103. \****************************************************************************/
  104.  
  105. void CALLING errAdd(int errorCode, unsigned functID)
  106. {
  107.     /* make sure that error list does not overflow */
  108.     if ( numErrors <= MAXERRORS )
  109.     {
  110.         /* store error information to list: */
  111.         errorList[numErrors].errorCode = errorCode;
  112.         errorList[numErrors].functID = functID;
  113.  
  114.         numErrors++;
  115.     }
  116. }
  117.  
  118.  
  119.  
  120.  
  121. /****************************************************************************\
  122. *
  123. * Function:     void errClearList(void)
  124. *
  125. * Description:  Clears the error list. Can be called if a error has been
  126. *               handled without exiting the program to avoid filling the
  127. *               error list with handled errors.
  128. *
  129. \****************************************************************************/
  130.  
  131. void CALLING errClearList(void)
  132. {
  133.     numErrors = 0;
  134. }
  135.  
  136.  
  137.  
  138.  
  139. /****************************************************************************\
  140. *
  141. * Function:     void errPrintList(void);
  142. *
  143. * Description:  Prints the error list to stderr
  144. *
  145. \****************************************************************************/
  146.  
  147. void CALLING errPrintList(void)
  148. {
  149.     unsigned    i;
  150.  
  151.     if ( numErrors > 0 )
  152.         fputs("MIDAS error list:\n", stderr);
  153.  
  154.     for ( i = 0; i < numErrors; i++ )
  155.     {
  156.         fprintf(stderr, "%u: <%i, %u> - %s at %u\n", i,
  157.             errorList[i].errorCode, errorList[i].functID,
  158.             errorMsg[errorList[i].errorCode], errorList[i].functID);
  159.     }
  160. }
  161.  
  162.  
  163.  
  164.  
  165.  
  166. #endif
  167.  
  168.  
  169. #ifdef __WATCOMC__
  170.  
  171. void SetMode3(void);
  172. #pragma aux SetMode3 = \
  173.         "mov    ax,0003h" \
  174.         "int    10h" \
  175.         modify exact [ax];
  176.  
  177. #endif
  178.  
  179.  
  180. /****************************************************************************\
  181. *
  182. * Function:     void errErrorExit(char *msg)
  183. *
  184. * Description:  Set up standard text mode, print an error message and exit
  185. *
  186. * Input:        char *msg               pointer to error message, ASCIIZ
  187. *
  188. \****************************************************************************/
  189.  
  190. void CALLING errErrorExit(char *msg)
  191. {
  192.     /* set up standard 80x25 text mode: */
  193. #ifdef __BORLANDC__
  194. asm     mov     ax,0003h
  195. asm     int     10h
  196. #else
  197. #ifdef __WATCOMC__
  198. //    SetMode3();
  199. #else
  200. #if (!defined(__LINUX__)) && (!defined(__WIN32__))
  201.     vgaSetMode(3);
  202. #endif
  203. #endif
  204. #endif
  205.  
  206.     fputs(msg, stderr);
  207.     fputs("\n", stderr);
  208.  
  209. #ifdef DEBUG
  210.     errPrintList();                     /* print error list */
  211. #endif
  212.  
  213.     /* exit to DOS: */
  214.     exit(EXIT_FAILURE);
  215. }
  216.  
  217.  
  218. /*
  219.  * $Log: errors.c,v $
  220.  * Revision 1.4  1996/07/13 20:33:43  pekangas
  221.  * Fixed for Visual C
  222.  *
  223.  * Revision 1.3  1996/05/24 20:40:12  jpaana
  224.  * Added USSWave
  225.  *
  226.  * Revision 1.2  1996/05/24 16:20:36  jpaana
  227.  * Added Linux specific stuff
  228.  *
  229.  * Revision 1.1  1996/05/22 20:49:33  pekangas
  230.  * Initial revision
  231.  *
  232. */